home *** CD-ROM | disk | FTP | other *** search
/ Stone Design / Stone Design.iso / Stone_Friends / Wave / WavesWorld / Source / Libraries / tcl7.4b3 / tclPort.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-01-10  |  6.3 KB  |  298 lines

  1. /*
  2.  * tclPort.h --
  3.  *
  4.  *    This header file handles porting issues that occur because
  5.  *    of differences between systems.  It reads in UNIX-related
  6.  *    header files and sets up UNIX-related macros for Tcl's UNIX
  7.  *    core.  It should be the only file that contains #ifdefs to
  8.  *    handle different flavors of UNIX.  This file sets up the
  9.  *    union of all UNIX-related things needed by any of the Tcl
  10.  *    core files.  This file depends on configuration #defines such
  11.  *    as NO_DIRENT_H that are set up by the "configure" script.
  12.  *
  13.  *    Much of the material in this file was originally contributed
  14.  *    by Karl Lehenbauer, Mark Diekhans and Peter da Silva.
  15.  *
  16.  * Copyright (c) 1991-1994 The Regents of the University of California.
  17.  * Copyright (c) 1994 Sun Microsystems, Inc.
  18.  *
  19.  * See the file "license.terms" for information on usage and redistribution
  20.  * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
  21.  *
  22.  * @(#) tclPort.h 1.4 94/12/17 16:14:53
  23.  */
  24.  
  25. #ifndef _TCLPORT
  26. #define _TCLPORT
  27.  
  28. #include <errno.h>
  29. #include <fcntl.h>
  30. #include <pwd.h>
  31. #include <signal.h>
  32. #include <sys/param.h>
  33. #include <sys/types.h>
  34. #ifdef USE_DIRENT2_H
  35. #   include "compat/dirent2.h"
  36. #else
  37. #   ifdef NO_DIRENT_H
  38. #    include "compat/dirent.h"
  39. #   else
  40. #    include <dirent.h>
  41. #   endif
  42. #endif
  43. #include <sys/file.h>
  44. #include <sys/stat.h>
  45. #ifndef NO_SYS_TIME_H
  46. #   include <sys/time.h>
  47. #else
  48. #   include <time.h>
  49. #endif
  50. #ifndef NO_SYS_WAIT_H
  51. #   include <sys/wait.h>
  52. #endif
  53. #ifdef HAVE_UNISTD_H
  54. #   include <unistd.h>
  55. #else
  56. #   include "compat/unistd.h"
  57. #endif
  58.  
  59. /*
  60.  * Not all systems declare the errno variable in errno.h. so this
  61.  * file does it explicitly.  The list of system error messages also
  62.  * isn't generally declared in a header file anywhere.
  63.  */
  64.  
  65. extern int errno;
  66.  
  67. /*
  68.  * The type of the status returned by wait varies from UNIX system
  69.  * to UNIX system.  The macro below defines it:
  70.  */
  71.  
  72. #ifdef AIX
  73. #   define WAIT_STATUS_TYPE pid_t
  74. #else
  75. #ifndef NO_UNION_WAIT
  76. #   define WAIT_STATUS_TYPE union wait
  77. #else
  78. #   define WAIT_STATUS_TYPE int
  79. #endif
  80. #endif
  81.  
  82. /*
  83.  * Supply definitions for macros to query wait status, if not already
  84.  * defined in header files above.
  85.  */
  86.  
  87. #ifndef WIFEXITED
  88. #   define WIFEXITED(stat)  (((*((int *) &(stat))) & 0xff) == 0)
  89. #endif
  90.  
  91. #ifndef WEXITSTATUS
  92. #   define WEXITSTATUS(stat) (((*((int *) &(stat))) >> 8) & 0xff)
  93. #endif
  94.  
  95. #ifndef WIFSIGNALED
  96. #   define WIFSIGNALED(stat) (((*((int *) &(stat)))) && ((*((int *) &(stat))) == ((*((int *) &(stat))) & 0x00ff)))
  97. #endif
  98.  
  99. #ifndef WTERMSIG
  100. #   define WTERMSIG(stat)    ((*((int *) &(stat))) & 0x7f)
  101. #endif
  102.  
  103. #ifndef WIFSTOPPED
  104. #   define WIFSTOPPED(stat)  (((*((int *) &(stat))) & 0xff) == 0177)
  105. #endif
  106.  
  107. #ifndef WSTOPSIG
  108. #   define WSTOPSIG(stat)    (((*((int *) &(stat))) >> 8) & 0xff)
  109. #endif
  110.  
  111. /*
  112.  * Define constants for waitpid() system call if they aren't defined
  113.  * by a system header file.
  114.  */
  115.  
  116. #ifndef WNOHANG
  117. #   define WNOHANG 1
  118. #endif
  119. #ifndef WUNTRACED
  120. #   define WUNTRACED 2
  121. #endif
  122.  
  123. /*
  124.  * Supply macros for seek offsets, if they're not already provided by
  125.  * an include file.
  126.  */
  127.  
  128. #ifndef SEEK_SET
  129. #   define SEEK_SET 0
  130. #endif
  131.  
  132. #ifndef SEEK_CUR
  133. #   define SEEK_CUR 1
  134. #endif
  135.  
  136. #ifndef SEEK_END
  137. #   define SEEK_END 2
  138. #endif
  139.  
  140. /*
  141.  * The stuff below is needed by the "time" command.  If this
  142.  * system has no gettimeofday call, then must use times and the
  143.  * CLK_TCK #define (from sys/param.h) to compute elapsed time.
  144.  * Unfortunately, some systems only have HZ and no CLK_TCK, and
  145.  * some might not even have HZ.
  146.  */
  147.  
  148. #ifdef NO_GETTOD
  149. #   include <sys/times.h>
  150. #   include <sys/param.h>
  151. #   ifndef CLK_TCK
  152. #       ifdef HZ
  153. #           define CLK_TCK HZ
  154. #       else
  155. #           define CLK_TCK 60
  156. #       endif
  157. #   endif
  158. #else
  159. EXTERN int        gettimeofday _ANSI_ARGS_((struct timeval *tp,
  160.                 struct timezone *tzp));
  161. #endif
  162.  
  163. /*
  164.  * Define access mode constants if they aren't already defined.
  165.  */
  166.  
  167. #ifndef F_OK
  168. #    define F_OK 00
  169. #endif
  170. #ifndef X_OK
  171. #    define X_OK 01
  172. #endif
  173. #ifndef W_OK
  174. #    define W_OK 02
  175. #endif
  176. #ifndef R_OK
  177. #    define R_OK 04
  178. #endif
  179.  
  180. /*
  181.  * Define FD_CLOEEXEC (the close-on-exec flag bit) if it isn't
  182.  * already defined.
  183.  */
  184.  
  185. #ifndef FD_CLOEXEC
  186. #   define FD_CLOEXEC 1
  187. #endif
  188.  
  189. /*
  190.  * On systems without symbolic links (i.e. S_IFLNK isn't defined)
  191.  * define "lstat" to use "stat" instead.
  192.  */
  193.  
  194. #ifndef S_IFLNK
  195. #   define lstat stat
  196. #endif
  197.  
  198. /*
  199.  * Define macros to query file type bits, if they're not already
  200.  * defined.
  201.  */
  202.  
  203. #ifndef S_ISREG
  204. #   ifdef S_IFREG
  205. #       define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
  206. #   else
  207. #       define S_ISREG(m) 0
  208. #   endif
  209. # endif
  210. #ifndef S_ISDIR
  211. #   ifdef S_IFDIR
  212. #       define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
  213. #   else
  214. #       define S_ISDIR(m) 0
  215. #   endif
  216. # endif
  217. #ifndef S_ISCHR
  218. #   ifdef S_IFCHR
  219. #       define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
  220. #   else
  221. #       define S_ISCHR(m) 0
  222. #   endif
  223. # endif
  224. #ifndef S_ISBLK
  225. #   ifdef S_IFBLK
  226. #       define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
  227. #   else
  228. #       define S_ISBLK(m) 0
  229. #   endif
  230. # endif
  231. #ifndef S_ISFIFO
  232. #   ifdef S_IFIFO
  233. #       define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
  234. #   else
  235. #       define S_ISFIFO(m) 0
  236. #   endif
  237. # endif
  238. #ifndef S_ISLNK
  239. #   ifdef S_IFLNK
  240. #       define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK)
  241. #   else
  242. #       define S_ISLNK(m) 0
  243. #   endif
  244. # endif
  245. #ifndef S_ISSOCK
  246. #   ifdef S_IFSOCK
  247. #       define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
  248. #   else
  249. #       define S_ISSOCK(m) 0
  250. #   endif
  251. # endif
  252.  
  253. /*
  254.  * Make sure that MAXPATHLEN is defined.
  255.  */
  256.  
  257. #ifndef MAXPATHLEN
  258. #   ifdef PATH_MAX
  259. #       define MAXPATHLEN PATH_MAX
  260. #   else
  261. #       define MAXPATHLEN 2048
  262. #   endif
  263. #endif
  264.  
  265. /*
  266.  * Make sure that L_tmpnam is defined.
  267.  */
  268.  
  269. #ifndef L_tmpnam
  270. #   define L_tmpnam 100
  271. #endif
  272.  
  273. /*
  274.  * Substitute Tcl's own versions for several system calls.  The
  275.  * Tcl versions retry automatically if interrupted by signals.
  276.  * (see tclUnixUtil.c).
  277.  */
  278.  
  279. #define open(a,b,c) TclOpen(a,b,c)
  280. #define read(a,b,c) TclRead(a,b,c)
  281. #define waitpid(a,b,c) TclWaitpid(a,b,c)
  282. #define write(a,b,c) TclWrite(a,b,c)
  283. EXTERN int    TclOpen _ANSI_ARGS_((char *path, int oflag, int mode));
  284. EXTERN int    TclRead _ANSI_ARGS_((int fd, VOID *buf, size_t numBytes));
  285. EXTERN int    TclWaitpid _ANSI_ARGS_((pid_t pid, int *statPtr, int options));
  286. EXTERN int    TclWrite _ANSI_ARGS_((int fd, VOID *buf, size_t numBytes));
  287.  
  288. /*
  289.  * Variables provided by the C library:
  290.  */
  291.  
  292. #if defined(_sgi) || defined(__sgi)
  293. #define environ _environ
  294. #endif
  295. extern char **environ;
  296.  
  297. #endif /* _TCLPORT */
  298.